/**
 * 苏州科达科技股份有限公司-监控产品线-门店业务开发组
 * <p>
 * Android Developer
 * <p>
 * Copyright (c) 1995-2014 All Rights Reserved.
 */
package com.ovopark.firecar.bean;


import androidx.annotation.NonNull;


import com.ovopark.firecar.common.Constants;

import java.io.Serializable;

/**
 * 邮箱： chentao@kedacom.com
 * <p>
 * 作者： 陈涛
 * <p>
 * 日期： 2014年9月3日
 * <p>
 * 描述： 用户实体类
 */
public class User implements Serializable, Comparable<User> {

    public static int PERSONAL_USER = 1;

    public static int ENTERPRISE_USER = 0;

    /**
     * 高管
     */
    public static int POSITION_MANAGE = -4;
    /**
     * 督导
     */
    public static int POSITION_SUPERVISOR = -3;
    /**
     * 店员，店长
     */
    public static int POSITION_CLERK = -2;
    /**
     * 专业线，不知道干嘛的，何老师说暂时和督导一样
     */
    public static int POSITION_SPECIAL = -1;

    private int dbid;

    private int id;

    //新token返回数据结构------------start-----------------
    private String token; //新toekn .
    private String oldToken;//老token 扫一扫等老接口暂时调用. 111111
    private Long tokenExpirationTimestamp; //token刷新时间戳.
    private Long refreshExpirationTimestamp; //token过期时间戳,需重新登录
    private Long createAtTimestamp = -1L;//刷新token的时间. 登录时候默认-1.
    private String version;//app版本号
    private String result;//
    private String errordescription;//错误描述
    private String signUsersId;
    private String webSocketId;
    private String registFlag;
    private String mobilePhone;//绑定的手机号
    //新token返回数据结构------------end-----------------

    private String userName;

    private String showName;

    private String thumbUrl;

    private String sortLetter;

    private String shortName;

    private int idLast;

    private String pyName;

    private int headerId;

    private int hasThumb;

    private int userType;

    private int isActivated;

    private int isSetProfile;

    private int checkType;

    private String email;

    private String phone;

    private String baiduChannelId;

    private String baiduUserId;

    private String address;

    private String description;

    private int fans;

    private int shares;

    private int follows;

    private int shops;

    private int favorShops;

    private int favorDevices;

    private boolean isFollowed;

    private boolean isSelected = false;

    private String registrationId;

    private String tel;

//    private List<Privileges> privileges;

    private String groupName;
    /**
     * 企业id
     */
    private String groupId;

    /**
     * 标识是否是常用联系人
     **/
    public boolean isRecentUser = false;

    private boolean isMyself = false;      //自定义标识是否为本人

    private int contactId = -1;            //自定义指向全部联系人和常用联系人位置

    private boolean isSecretary = false;   //工作圈是否为小秘书

    private boolean isUnChanged = false;    //自定义标识是否不能改动

    private int enterpriseId;
    /**
     * 是否为签到申请审核人
     */
    public boolean isApprover = false;
    /**
     * 角色职级
     */
    private Integer gradeId;

    private String tlsName;//IM登陆新标识 之前用userName 会有中文出现
    private int superior;//文件模块 1父级管理员子级不能操作

    private String organizeName;

    /**
     * 客服系统token
     */
    private String customerToken;


    /**
     * IM系统token
     */
    private String imToken;

    private String staffImageUrl;//员工基准照

    private String validateDate;//企业到期时间   2026-06-26T00:00:00

    private boolean tokenRefreshing = false;//token是否正在刷新.

    private String pyFirst;//拼音首字母缩写
    /**
     * 2021年6月7日新增
     * 给个初始值=1，不然会导致更新后打开APP都要修改密码
     */
    private int pwdPower = 1;//0：为初始密码，1：非初始密码

    public User() {

    }

    public User(UserBo userBo) {
        setId(userBo.getUserId());
        setThumbUrl(userBo.getPicture());
        setShowName(userBo.getShowName());
        setUserName(userBo.getUserName());
        setShortName(userBo.getShortName());
    }


    public boolean isTokenRefreshing() {
        return tokenRefreshing;
    }

    public void setTokenRefreshing(boolean tokenRefreshing) {
        this.tokenRefreshing = tokenRefreshing;
    }

    /**
     * 是否应该刷新token.
     *
     * @return
     */
    public boolean isNeedRefreshToken() {
        if (null != tokenExpirationTimestamp) {
            long expireTime = tokenExpirationTimestamp - System.currentTimeMillis();
            //提前5分钟刷洗token。
            return expireTime <= Constants.PREVIOUS_REFRESH_TOKEN_TIME * 10;
        }

        return false;
    }

    /**
     * 是否应该重新登陆.
     *
     * @return
     */
    public boolean isNeedReLoginToken() {

        if (null != refreshExpirationTimestamp) {
            long expireTime = refreshExpirationTimestamp - System.currentTimeMillis();
            //提前10分钟踢出用户。
            return expireTime <= Constants.PREVIOUS_REFRESH_TOKEN_TIME * 20;
        }

        return false;
    }


    /**
     * 刷新过期时间.
     *
     * @return
     */
    public Long getTokenExpirationTimestamp() {
        return tokenExpirationTimestamp;
    }

    public Long getCreateAtTimestamp() {
        return createAtTimestamp;
    }

    public void setCreateAtTimestamp(Long createAtTimestamp) {
        this.createAtTimestamp = createAtTimestamp;
    }

    public void setTokenExpirationTimestamp(Long tokenExpirationTimestamp) {
        this.tokenExpirationTimestamp = tokenExpirationTimestamp;
    }

    /**
     * 需要登录获取token的时间，
     * 到时候token全部失效，刷新无效.
     *
     * @return
     */
    public Long getRefreshExpirationTimestamp() {
        return refreshExpirationTimestamp;
    }

    public void setRefreshExpirationTimestamp(Long refreshExpirationTimestamp) {
        this.refreshExpirationTimestamp = refreshExpirationTimestamp;
    }

    public String getVersion() {
        return version;
    }

    public void setVersion(String version) {
        this.version = version;
    }

    public String getResult() {
        return result;
    }

    public void setResult(String result) {
        this.result = result;
    }

    public String getErrordescription() {
        return errordescription;
    }

    public void setErrordescription(String errordescription) {
        this.errordescription = errordescription;
    }

    public String getSignUsersId() {
        return signUsersId;
    }

    public void setSignUsersId(String signUsersId) {
        this.signUsersId = signUsersId;
    }

    public String getWebSocketId() {
        return webSocketId;
    }

    public void setWebSocketId(String webSocketId) {
        this.webSocketId = webSocketId;
    }

    public String getRegistFlag() {
        return registFlag;
    }

    public void setRegistFlag(String registFlag) {
        this.registFlag = registFlag;
    }

    public Integer getGradeId() {
        return gradeId;
    }

    public void setGradeId(Integer gradeId) {
        this.gradeId = gradeId;
    }

    public String getGroupId() {
        return groupId;
    }

    public void setGroupId(String groupId) {
        this.groupId = groupId;
    }

    public String getTel() {
        return tel;
    }

    public void setTel(String tel) {
        this.tel = tel;
    }

    public String getEnterpriseId() {
        return groupId;
    }

    public void setEnterpriseId(int enterpriseId) {
        this.enterpriseId = enterpriseId;
    }

    public boolean isSecretary() {
        return isSecretary;
    }

    public void setSecretary(boolean secretary) {
        isSecretary = secretary;
    }

    public int getContactId() {
        return contactId;
    }

    public void setContactId(int contactId) {
        this.contactId = contactId;
    }

    public boolean isUnChanged() {
        return isUnChanged;
    }

    public void setUnChanged(boolean unChanged) {
        isUnChanged = unChanged;
    }

    public boolean isMyself() {
        return isMyself;
    }

    public void setMyself(boolean myself) {
        isMyself = myself;
    }

    public int getIdLast() {
        return idLast;
    }

    public void setIdLast(int idLast) {
        this.idLast = idLast;
    }

    public String getShortName() {
        return shortName;
    }

    public void setShortName(String shortName) {
        this.shortName = shortName;
    }

    public int getDbid() {
        return dbid;
    }

    public void setDbid(int dbid) {
        this.dbid = dbid;
    }

    public String getRegistrationId() {
        return registrationId;
    }

    public void setRegistrationId(String registrationId) {
        this.registrationId = registrationId;
    }

    public boolean isSelected() {
        return isSelected;
    }

    public void setSelected(boolean isSelected) {
        this.isSelected = isSelected;
    }

    public int getHeaderId() {
        return headerId;
    }

    public void setHeaderId(int headerId) {
        this.headerId = headerId;
    }

    public String getSortLetter() {
        return sortLetter;
    }

    public void setSortLetter(String sortLetter) {
        this.sortLetter = sortLetter;
    }

    public String getShowName() {
        return showName;
    }

    public void setShowName(String showName) {
        this.showName = showName;
    }

    public int getShops() {
        return shops;
    }

    public void setShops(int shops) {
        this.shops = shops;
    }

    public int getFavorShops() {
        return favorShops;
    }

    public void setFavorShops(int favorShops) {
        this.favorShops = favorShops;
    }

    public int getFavorDevices() {
        return favorDevices;
    }

    public void setFavorDevices(int favorDevices) {
        this.favorDevices = favorDevices;
    }

    public int getId() {
        return id;
    }

    public int getHasThumb() {
        return hasThumb;
    }

    public int getUserType() {
        return userType;
    }

    public int getIsActivated() {
        return isActivated;
    }

    public int getIsSetProfile() {
        return isSetProfile;
    }

    public String getEmail() {
        return email;
    }

    public String getToken() {
        return token;
    }

    public String getPhone() {
        return phone;
    }

    public String getBaiduChannelId() {
        return baiduChannelId;
    }

    public String getBaiduUserId() {
        return baiduUserId;
    }

    public String getAddress() {
        return address;
    }

    public String getUserName() {
        return userName;
    }

    public String getDescription() {
        return description;
    }

    public String getThumbUrl() {
        return thumbUrl;
    }

    public int getFans() {
        return fans;
    }

    public int getShares() {
        return shares;
    }

    public int getFollows() {
        return follows;
    }

    public void setId(int id) {
        this.id = id;
    }

    public void setHasThumb(int hasThumb) {
        this.hasThumb = hasThumb;
    }

    public void setUserType(int userType) {
        this.userType = userType;
    }

    public void setIsActivated(int isActivated) {
        this.isActivated = isActivated;
    }

    public void setIsSetProfile(int isSetProfile) {
        this.isSetProfile = isSetProfile;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public String getOldToken() {
        return oldToken;
    }

    public void setOldToken(String oldToken) {
        this.oldToken = oldToken;
    }

    /**
     * 更新刷新token所需要的的关键信息.
     *
     * @param user
     */
    public void refreshTokenInfo(UserToken user) {

        this.refreshTokenInfo(user.getToken(),
                user.getCreateAtTimestamp(),
                user.getRefreshExpirationTimestamp(),
                user.getTokenExpirationTimestamp());
    }

    /**
     * 获取token刷新的相关信息.
     *
     * @return
     */
    public UserToken getTokenInfo() {
        UserToken userToken = new UserToken();

        userToken.setToken(getToken());
        userToken.setCreateAtTimestamp(getCreateAtTimestamp());
        userToken.setRefreshExpirationTimestamp(getRefreshExpirationTimestamp());
        userToken.setTokenExpirationTimestamp(getTokenExpirationTimestamp());

        return userToken;
    }

    /**
     * 更新刷新token所需要的的关键信息.
     */
    public void refreshTokenInfo(String newToken, Long createAtTimestamp, Long refreshExpirationTimestamp, Long tokenExpirationTimestamp) {
        this.setToken(newToken);
        this.setTokenExpirationTimestamp(tokenExpirationTimestamp);
        this.setRefreshExpirationTimestamp(refreshExpirationTimestamp);
        this.setCreateAtTimestamp(createAtTimestamp);
    }


    public void setPhone(String phone) {
        this.phone = phone;
    }

    public void setBaiduChannelId(String baiduChannelId) {
        this.baiduChannelId = baiduChannelId;
    }

    public void setBaiduUserId(String baiduUserId) {
        this.baiduUserId = baiduUserId;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public void setThumbUrl(String thumbUrl) {
        this.thumbUrl = thumbUrl;
    }

    public String getStaffImageUrl() {
        return staffImageUrl;
    }

    public void setStaffImageUrl(String staffImageUrl) {
        this.staffImageUrl = staffImageUrl;
    }

    public void setFans(int fans) {
        this.fans = fans;
    }

    public void setShares(int shares) {
        this.shares = shares;
    }

    public void setFollows(int follows) {
        this.follows = follows;
    }

    public boolean isFollowed() {
        return isFollowed;
    }

    public void setFollowed(boolean isFollowed) {
        this.isFollowed = isFollowed;
    }

    public int getCheckType() {
        return checkType;
    }

    public void setCheckType(int checkType) {
        this.checkType = checkType;
    }

    public String getPyName() {
        return pyName;
    }

    public void setPyName(String pyName) {
        this.pyName = pyName;
    }

    public String getGroupName() {
        return groupName;
    }

    public void setGroupName(String groupName) {
        this.groupName = groupName;
    }

    public String getTlsName() {
        return tlsName;
    }

    public void setTlsName(String tlsName) {
        this.tlsName = tlsName;
    }

    public int getSuperior() {
        return superior;
    }

    public void setSuperior(int superior) {
        this.superior = superior;
    }

    public boolean isRecentUser() {
        return isRecentUser;
    }

    public void setRecentUser(boolean recentUser) {
        isRecentUser = recentUser;
    }

    public boolean isApprover() {
        return isApprover;
    }

    public void setApprover(boolean approver) {
        isApprover = approver;
    }

    public String getOrganizeName() {
        return organizeName;
    }

    public void setOrganizeName(String organizeName) {
        this.organizeName = organizeName;
    }

    @Override
    public int compareTo(@NonNull User arg0) {
        return this.getSortLetter().compareTo(arg0.getSortLetter());
    }

    @Override
    public boolean equals(Object obj) {
        return this.id == ((User) obj).getId();
    }

    public String getCustomerToken() {
        return customerToken;
    }

    public void setCustomerToken(String customerToken) {
        this.customerToken = customerToken;
    }

    public String getImToken() {
        return imToken;
    }

    public void setImToken(String imToken) {
        this.imToken = imToken;
    }

    public String getValidateDate() {
        return validateDate;
    }

    public void setValidateDate(String validateDate) {
        this.validateDate = validateDate;
    }

    public String getPyFirst() {
        return pyFirst;
    }

    public void setPyFirst(String pyFirst) {
        this.pyFirst = pyFirst;
    }

    public int getPwdPower() {
        return pwdPower;
    }

    public void setPwdPower(int pwdPower) {
        this.pwdPower = pwdPower;
    }

    public String getMobilePhone() {
        return mobilePhone;
    }

    public void setMobilePhone(String mobilePhone) {
        this.mobilePhone = mobilePhone;
    }
}